#include <REGX52.H>
#include "ONEWIRE.H"

#define DS18B20_SKIP_ROM 0XCC
#define DS18B20_CONVERT_T 0x44
#define DS18B20_SCRATCHPAD 0xBE

void DS18B20_Convert(void)
{
	OneWire_Init();
	OneWire_SendByte(DS18B20_SKIP_ROM);
	OneWire_SendByte(DS18B20_CONVERT_T);
}

float DS18B20_Read(void)
{
	unsigned char TLSB;
	unsigned char TMSB;
	int Temp;
	float T;
	OneWire_Init();
	OneWire_SendByte(DS18B20_SKIP_ROM);
	OneWire_SendByte(DS18B20_SCRATCHPAD);
	//发出0xBE指令，SCRATCHPAD寄存器1会将地址中Byte0~7中的数据依次发出
	TLSB=OneWire_ReceiveByte();
	TMSB=OneWire_ReceiveByte();
	Temp=(TMSB<<8)|TLSB;
	T=Temp/16.0;//消除int Temp对小数的影响，即右移四位
	return T;
}